//
//  MyMessageTableViewCell.m
//  Liuhe
//
//  Created by zr on 2018/8/21.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyMessageTableViewCell.h"


@interface MyMessageTableViewCell ()

@property(nonatomic, weak)UIImageView * iconImageView;
@property(nonatomic, weak)UILabel * nameLabel;
@property(nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UIView * lineView;

@end


@implementation MyMessageTableViewCell


- (void)setModel:(MyMessageModel *)model{
    
    _model = model;
    
//    NSLog(@"===%@",model.user_name);
    
    self.nameLabel.text = model.user_name;
    self.titleLabel.text = model.title;
    
    NSURL * url = [NSURL URLWithString:model.user_headimg];
    
    [self.iconImageView sd_setImageWithURL:url placeholderImage:ImageNamed(@"23sdasas")];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}



- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor whiteColor];
    
    
    UIImageView * iconImageView = [UIImageView new];
    
    //  把图片设置成圆形
    iconImageView.layer.cornerRadius = 35;//裁成圆角
    iconImageView.layer.masksToBounds = YES;//隐藏裁剪掉的部分
    
    iconImageView.image = ImageNamed(@"23sdasas");
    //    iconImageView.backgroundColor = [UIColor redColor];
    
    self.iconImageView = iconImageView;
    
    [self.contentView addSubview:self.iconImageView];
 
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.text = @"用户姓名";
    nameLabel.textColor = BLACK_COLOR;
    nameLabel.font = [UIFont systemFontOfSize:17 * SCREENH6];
    
    self.nameLabel = nameLabel;
    
    [self.contentView addSubview:self.nameLabel];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"用户姓名";
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
}


- (void)layoutSubviews{
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.contentView).offset(10 * SCREENH6);
        make.width.height.mas_equalTo(70 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconImageView);
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.iconImageView);
        make.leading.mas_equalTo(self.nameLabel);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
